import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:lite_message/util/app_util.dart';
import 'package:lite_message/widgets/back_icon.dart';

///自定义应用背景
class CustomBg extends StatelessWidget {
  final Color backgroundColor;
  final Color appBarColor;
  final Widget body;
  final String title;
  final Widget customTitle;

  final Widget action;

  final Brightness brightness;

  ///是否显示返回按钮
  final bool showBack;

  ///是否显示应用栏
  final bool showAppBar;

  ///应用栏边距
  final EdgeInsetsGeometry appBarPadding;

  const CustomBg({
    Key key,
    this.backgroundColor,
    @required this.body,
    this.showAppBar = true,
    this.appBarColor = Colors.transparent,
    this.showBack = true,
    this.action,
    this.brightness,
    this.appBarPadding,
    this.title,
    this.customTitle,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    ///默认应用栏高度
    final double _cToolBarHeight = 160.px;

    return GestureDetector(
      onTap: () => LM.unFocus(context),
      child: Scaffold(
        primary: false,
        backgroundColor: backgroundColor ?? Theme.of(context).canvasColor,
        appBar: AppBar(
          toolbarHeight: 0,
          brightness: brightness,
          elevation: 0,
          automaticallyImplyLeading: false,
        ),
        body: Column(
          children: [
            showAppBar
                ? Container(
                    height: 320.px,
                    padding: appBarPadding ??
                        EdgeInsets.fromLTRB(90.px, 0, 90.px, 20.px),
                    width: double.infinity,
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.end,
                      children: [
                        showBack
                            ? BackIcon(size: _cToolBarHeight)
                            : SizedBox(width: _cToolBarHeight),
                        Expanded(
                          child: Container(
                            height: _cToolBarHeight,
                            alignment: Alignment.center,
                            child: customTitle ??
                                Text(
                                  '${title ?? ''}',
                                  style: TextStyle(
                                    color: Theme.of(context).accentColor,
                                    fontSize: 60.sp,
                                    fontWeight: FontWeight.bold,
                                  ),
                                ),
                          ),
                        ),
                        SizedBox(
                          width: _cToolBarHeight,
                          height: _cToolBarHeight,
                          child: action ?? Container(),
                        ),
                      ],
                    ),
                  )
                : Container(),
            Expanded(child: body),
          ],
        ),
      ),
    );
  }
}
